class Solution {
public:
    int wiggleMaxLength(vector<int>& nums) {
        const int m = nums.size();
        vector<int> f(m, 1);
        auto g = f;

        int ret = 1;

        for(int i = 1; i < m; ++i)
        {
            for(int j = 0; j < i; ++j)
            {
                if(nums[i] > nums[j])
                    f[i] = max(g[j] + 1, f[i]);
                else if(nums[j] > nums[i])
                    g[i] = max(f[j] + 1, g[i]);
            } 
            ret = max({ ret, g[i], f[i] });
        }

        return ret;
    }
};
